# -*- coding: utf-8 -*-
from zope.location.interfaces import IRoot
from pargo.interfaces import IContentImporter, IContent
from pargo.utils.view import View
from pargo.content.site import Site

class ZipImportView(View):
    """
    Initiates importing content from zip.
    """
    
    def render(self):
        filename = self.request.params.get('fn')
        if not filename:
            return 'False'

        context = self.context
        if not IContent.providedBy(context):
            if IRoot.providedBy(context):
                context['site'] = Site()
                context = context['site']
            else:
                raise ValueError('Not possible to add content here')

        importer = IContentImporter(context)
        return str(importer.do_import(filename))
